<template>
	<view class="contain">
		<view class="header">
			<view class="">
				<u-search placeholder="搜索场地关键字" v-model="keyword" @search="reverseCouty" :show-action="false" class="header-search"></u-search>
			</view>
			<view class="header-select">
				<view class="select-button u-text-right" @click="selectAndDown">
					<text>筛选</text>
					<u-icon name="arrow-down"></u-icon>
				</view>
				<view :class="hidden?'hidden-selectBox':'selectBox'">
					<view :class="value==index?'selectBoxActive':''"  v-for="(item,index) in select" @click="selectItem(index)">
						{{item}}
						<u-icon name="checkbox-mark" v-if="value==index" class="u-p-l-40 select-u-icon"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<view class="venue">
			<view class="venue-list" v-for="(item,index) in venue" @click="venueDetails(item.placeid)">
				<view style="position: absolute;top:0;z-index=5;background: -webkit-linear-gradient(left bottom,rgba(90, 89, 189,0),rgba(90, 89, 189,0.3));width: 750rpx;height: 200rpx;"></view>
				<h3>{{item.placename}}</h3>
				<view class="venue-tag"><text>{{item.placetype}}</text></view>
				<view class="venue-person-num">
					<text>当前预约人数:{{item.ordernum}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				false: false,
				keyword: "",
				value: 0,
				hidden: true,
				select:[
					"所有场地",
					"无人预约",
					"已有预约"
				],
				venue:[
				],
				venue1:[]
			}
		},
		onLoad() {
			this.getAllVenue();
		},
		onTabItemTap(e){
			// // console.log(e);
			this.getAllVenue();
		},
		onPullDownRefresh() {
				setTimeout(function () {
					// this.getAllVenue()
					uni.stopPullDownRefresh();
				}, 1000);
			},
		methods: {
			async getAllVenue() {
				const res = await this.$myRequest({
					url: 'PlaceController/queryplacebyname',
					data:{
						push:1
					}
				})
				this.venue1=res.data;
				this.venue=res.data;
				console.log(res);
			},
			open(index) {
				// 展开某个下来菜单时，先关闭原来的其他菜单的高亮
				// 同时内部会自动给当前展开项进行高亮
				this.$refs.uDropdown.highlight();
			},
			close(index) {
				// 关闭的时候，给当前项加上高亮
				// 当然，您也可以通过监听dropdown-item的@change事件进行处理
				this.$refs.uDropdown.highlight(index);
			},
			change(){
				if(this.value===2){
					// this.getAllVenue();
					for(var i=0;i<this.venue.length;){
						if(this.venue[i].ordernum!==0){
							this.venue.splice(i,1);
						}
						else{
							i++;
						}
					}
					
				}
				else if(this.value===3){
					// 
					for(var i=0;i<this.venue.length;){
						// console.log(this.venue.length);
						if(this.venue.length==1&&this.venue[length-1]==0){
							this.venue=[];
							break;
						}
						if(this.venue[i].ordernum==0){
							this.venue.splice(i,1);
						}
						
						else{
							i++;
						}
					}
				}
			},
			selectAndDown(){
				this.hidden=!this.hidden;
			},
			selectItem(index){
				this.venue=JSON.parse(JSON.stringify(this.venue1))
				if(index==0){
					this.value=0;
				}
				else if(index==1){
					this.value=1;
					for(var i=0;i<this.venue.length;){
						if(this.venue[i].ordernum!==0){
							this.venue.splice(i,1);
						}
						else{
							i++;
						}
					}
				}
				else if(index==2){
					this.value=2;
					for(var i=0;i<this.venue.length;){
						// console.log(this.venue.length);
						if(this.venue.length==1&&this.venue[length-1]==0){
							this.venue=[];
							break;
						}
						if(this.venue[i].ordernum==0){
							this.venue.splice(i,1);
						}
						
						else{
							i++;
						}
					}
				}
				this.hidden=!this.hidden;
			},
			async reverseCouty(){
				// console.log(this.keyword);
				const res = await this.$myRequest({
					url: 'PlaceController/queryplacebyname',
					data:{
						placename:this.keyword,
						push:1
					},
					method:"POST"
				})
				this.venue1=res.data;
				console.log(res)
				this.venue=res.data;
				// console.log(res);
			},
			venueDetails(placeid){
				uni.navigateTo({
					url: '/pages/venuedetails/venuedetails?id='+placeid,
				});
			}
		}
	}
</script>

<style lang="scss">
	page{
		overflow:hidden;
	}
	.contain{
		min-height: 350rpx;
		image{
			width: 100%;
			height: 100rpx;
		}
	}
	.image{
		width: 100rpx;
		height: 100rpx;
	}
	.header {
		margin: 10rpx;
		.header-select {
			position: relative;
			color:#333;
			.select-button{
				margin: 20rpx 0;
				margin-right: 30rpx;
				.u-icon{
					margin-left: 5rpx;
					display: inline-block;
				}
			}
			.selectBox{
				background-color: #fff;
				width: 200rpx;
				position:absolute;
				top:50rpx;
				right: -10rpx;
				z-index: 3;
				border-top: 1px solid $uni-border-color;
				border-left: 1px solid $uni-border-color;
				view{
					height: 60rpx;
					padding-left: 5rpx;
					line-height: 60rpx;
					border-bottom: 1px solid $uni-border-color;
					.select-u-icon{
						border-bottom: none;
					}
				}
				.selectBoxActive{
					color: $u-type-primary;
				}
			}
			.hidden-selectBox{
				display: none;
			}
		}
	}
	.venue{
		.venue-list{
			position: relative;
			width: 750rpx;
			height: 200rpx;
			margin-bottom: 10rpx;
			// background-color: red;
			border-top: 1px solid $uni-border-color;
			border-bottom: 1px solid $uni-border-color;
			h3{
				margin: 40rpx 0 0 20rpx;
			}
			.venue-tag{
				position: absolute;
				top:45rpx;
				right: 40rpx;
				height: 40rpx;
				width: 60rpx;
				color:#fff;
				text-align: center;
				border-radius: 8rpx;
				background-color: $uni-color-warning;
				text{
					font-size: 18rpx;
				}
			}
			.venue-person-num{
				position: absolute;
				bottom: 20rpx;
				right: 30rpx;
			}
		}
	}
</style>
